<?php
//array_map('unlink', ['/tmp/1.txt', '/tmp/2.txt']);

$rows = [
    ['id' => 5],
    ['id' => 7],
];
$idArray = array_map(function ($item) {
    return $item['id'];
}, $rows);
print_r($idArray);
/**
 * Array
 * (
 * [0] => 5
 * [1] => 7
 * )
 */


$lines = [
    'Whatever is worth doing is worth doing well',
    'The hard part isn’t making the decision. It’s living with it',
    'Life is a journey, not the destination, but the scenery along the should be and the mood at the view',
];
echo max(array_map('strlen', $lines)) . "\n";
/**
 * 100
 */

print_r(array_map('strtolower', ['Berlin', 'KYIV', 'Amsterdam', 'Riga']));
/**
 * Array
 * (
 * [0] => berlin
 * [1] => kyiv
 * [2] => amsterdam
 * [3] => riga
 * )
 */

print_r(array_map(function ($number) {
    return $number ** 2;
}, [1, - 2, 3, - 4, 5]));
/**
 * Array
 * (
 * [0] => 1
 * [1] => 4
 * [2] => 9
 * [3] => 16
 * [4] => 25
 * )
 */

$model = ['id' => 7, 'name' => 'James'];
print_r(array_map(function ($key, $value) {
    return $key . ' is ' . $value;
}, array_keys($model), $model));
/**
 * Array
 * (
 * [0] => id is 7
 * [1] => name is James
 * )
 */

//$resultArray = [];
//array_walk($urls, function ($url) use (&$resultArray) {
//    $resultArray[] = file_get_contents($url);
//});

$array = ['name', 'yeedom'];
array_walk($array, function (&$val) {
    $val = [$val];
});
var_export($array);
[
    0 => [
        0 => 'name',
    ],
    1 => [
        0 => 'yeedom',
    ],
];

$array = ['name' => 'yeedomliu', 'sex' => 'male'];
array_walk($array, function ($val, $key, $custom) {
    echo "{$key}:{$val}:{$custom['hair']}:{$custom['weight']}\n";
}, ['hair' => 'short', 'weight' => '150']);
/**
 * name:yeedomliu:short:150
 * sex:male:short:150
 */

$array = ['name' => 'yeedomliu', 'sex' => 'male'];
$custom = ['hair' => 'short', 'weight' => '150'];
array_walk($array, function ($val, $key) use ($custom) {
    echo "{$key}:{$val}:{$custom['hair']}:{$custom['weight']}\n";
});
/**
 * name:yeedomliu:short:150
 * sex:male:short:150
 */

$helpArray = [
    ['generate:cept' => 'Generates empty Cept file in suite'],
    ['generate:environment' => 'Generates empty environment config'],
    ['generate:helper' => 'Generates new helper'],
];
echo array_reduce($helpArray, function ($carry, $row) {
    return $carry . str_pad(key($row), 25) . current($row) . "\n";
}, '');
/**
 * generate:cept            Generates empty Cept file in suite
 * generate:environment     Generates empty environment config
 * generate:helper          Generates new helper
 */

$isIntArray = array_reduce([1, 3, 5], function ($carry, $val) {
    return $carry && is_numeric($val);
}, true);
var_dump($isIntArray);
/**
 * bool(true)
 */

$isIntArray = array_reduce([1, 3, 'string'], function ($carry, $val) {
    return $carry && is_numeric($val);
}, true);
var_dump($isIntArray);
/**
 * bool(false)
 */

$wordArray = [[1, 3, 5], ['name', 'sex']];
$wordCount = array_reduce($wordArray, function ($carry, $item) {
    return $carry + count($item);
}, 0);
echo $wordCount . "\n";
/**
 * 5
 */